<div class="tabbable tabs-left">
    <ul class="nav nav-tabs">
        <li><h5><?php echo $this->translate('广告'); ?></h5></li>
        <li class="active"><a data-toggle="tab" href="#ad_a"><?php echo $this->translate('基本信息'); ?></a></li>
    </ul>
    <form class="form-horizontal" name="ad_form" id="ad_form" method="post" enctype="multipart/form-data" action="">
        <input type="hidden" name="dbapi_ad_code" id="dbapi_ad_code" value="<?php echo $this->ad['code']; ?>" />
        <input type="hidden" name="dbapi_ad_id" id="dbapi_ad_id" value="<?php echo isset($this->ad['dbapi_ad_id']) ? $this->ad['dbapi_ad_id'] : ''; ?>">
        <div class="tab-content">
            <div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
                <div class="pull-left" style="font-size:16px;line-height:30px;"><strong><?php echo $this->translate('设置'); ?><?php echo $this->translate('广告'); ?></strong></div>
                <div class="pull-right">
                    <a href="<?php echo $this->url('dbapi/default', array('action'=>'adIndex')); ?>" class="btn btn-small"><i class="icon-arrow-left"></i> <?php echo $this->translate('返回广告设置'); ?></a>&nbsp;
                    <a href="<?php echo $this->serverUrl(true); ?>" class="btn btn-small btn-warning"><i class="icon-repeat icon-white"></i> <?php echo $this->translate('刷新'); ?></a>&nbsp;
                    <button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存广告信息'); ?></button>&nbsp;
                </div>
            </div>
            <div id="ad_a" class="tab-pane active">
                <div class="well admin_add_header_well"><?php echo $this->translate('基本信息'); ?></div>
                <div class="well admin_add_well">
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('调用名称'); ?>：</label>
                        <div class="controls">
                            <label style="line-height: 28px;"><?php echo $this->ad['name']; ?></label>
                        </div>
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('广告类型'); ?><span class="must_add_value">*</span>：</label>
                        <div class="controls">
                            <select name="dbapi_ad_type" id="dbapi_ad_type" class="span2" onchange="change_ad_type();">
                                <option value=""><?php echo $this->translate('请选择广告类型'); ?></option>
                                <option value="image" <?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'image') echo 'selected="selected"'; ?>><?php echo $this->translate('图片'); ?></option>
                                <option value="text" <?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'text') echo 'selected="selected"'; ?>><?php echo $this->translate('文字'); ?></option>
                                <option value="code" <?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'code') echo 'selected="selected"'; ?>><?php echo $this->translate('代码'); ?></option>
                                <option value="slide" <?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'slide') echo 'selected="selected"'; ?>><?php echo $this->translate('幻灯片'); ?></option>
                            </select>
                            &nbsp;&nbsp;<span id="recom_image_size"></span>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_image" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('广告图片'); ?>：</label>
                        <div class="controls">
                            <?php if(!empty($this->ad['dbapi_ad_body'])) { ?>
                                <img src="<?php echo $this->basePath($this->ad['dbapi_ad_body']); ?>" border="0" style="max-width:500px;" />
                                <input type="hidden" name="old_ad_image" value="<?php echo $this->ad['dbapi_ad_body']; ?>" />
                                <br />
                            <?php } ?>
                            <input type="file" name="ad_image" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_text" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('广告文字'); ?>：</label>
                        <div class="controls">
                            <script type="text/plain" id="ad_text" name="ad_text"><?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'text') echo $this->ad['dbapi_ad_body'] ?></script>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_code" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('广告代码'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_code" id="ad_code" rows="3"><?php if(isset($this->ad['dbapi_ad_type']) and $this->ad['dbapi_ad_type'] == 'code') echo $this->ad['dbapi_ad_body']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('幻灯片图片1'); ?>：</label>
                        <div class="controls">
                            <?php $slide_content_0 = false; if($this->slide_array and !empty($this->slide_array[0])) { $slide_content_0 = true;
                                $file1_md5_str = md5($this->slide_array[0]['dbapi_ad_slide_image']);
                                ?>
                                <img class="<?php echo $file1_md5_str; ?>" src="<?php echo $this->basePath($this->slide_array[0]['dbapi_ad_slide_image']); ?>" border="0" style="max-width:500px;" />
                                <a href="javascript:;" class="badge badge-important <?php echo$file1_md5_str; ?>" onclick="del_slide_image(<?php echo $this->ad['dbapi_ad_id']; ?>, '<?php echo $this->slide_array[0]['dbapi_ad_slide_image']; ?>');" title="<?php echo $this->translate('删除图片'); ?>">X</a>
                                <input class="<?php echo $file1_md5_str; ?>" type="hidden" name="old_ad_slide_image_1" value="<?php echo $this->slide_array[0]['dbapi_ad_slide_image']; ?>" />
                                <br class="<?php echo $file1_md5_str; ?>" />
                            <?php } ?>
                            <input type="file" name="ad_slide_image_1" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('显示文字1'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_slide_text_1" rows="2"><?php if($slide_content_0) echo $this->slide_array[0]['dbapi_ad_slide_info']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('链接地址1'); ?>：</label>
                        <div class="controls">
                            <input type="text"  name="ad_slide_url_1" class="span8" value="<?php if($slide_content_0) echo $this->slide_array[0]['dbapi_ad_slide_url']; ?>">
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('排序1'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="ad_slide_sort_1" value="<?php echo ($slide_content_0 ? $this->slide_array[0]['dbapi_ad_slide_sort'] : 1); ?>" class="span1" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('幻灯片图片2'); ?>：</label>
                        <div class="controls">
                            <?php $slide_content_1 = false; if($this->slide_array and !empty($this->slide_array[1])) { $slide_content_1 = true;
                                $file2_md5_str = md5($this->slide_array[1]['dbapi_ad_slide_image']);
                                ?>
                                <img class="<?php echo $file2_md5_str; ?>" src="<?php echo $this->basePath($this->slide_array[1]['dbapi_ad_slide_image']); ?>" border="0" style="max-width:500px;" />
                                <a href="javascript:;" class="badge badge-important <?php echo $file2_md5_str; ?>" onclick="del_slide_image(<?php echo $this->ad['dbapi_ad_id']; ?>, '<?php echo $this->slide_array[1]['dbapi_ad_slide_image']; ?>');" title="<?php echo $this->translate('删除图片'); ?>">X</a>
                                <input class="<?php echo $file2_md5_str; ?>" type="hidden" name="old_ad_slide_image_2" value="<?php echo $this->slide_array[1]['dbapi_ad_slide_image']; ?>" />
                                <br class="<?php echo $file2_md5_str; ?>" />
                            <?php } ?>
                            <input type="file" name="ad_slide_image_2" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('显示文字2'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_slide_text_2" rows="2"><?php if($slide_content_1) echo $this->slide_array[1]['dbapi_ad_slide_info']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('链接地址2'); ?>：</label>
                        <div class="controls">
                            <input type="text"  name="ad_slide_url_2" class="span8" value="<?php if($slide_content_1) echo $this->slide_array[1]['dbapi_ad_slide_url']; ?>">
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('排序2'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="ad_slide_sort_2" value="<?php echo ($slide_content_1 ? $this->slide_array[1]['dbapi_ad_slide_sort'] : 2); ?>" class="span1" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('幻灯片图片3'); ?>：</label>
                        <div class="controls">
                            <?php $slide_content_2 = false; if($this->slide_array and !empty($this->slide_array[2])) { $slide_content_2 = true;
                                $file3_md5_str = md5($this->slide_array[2]['dbapi_ad_slide_image']);
                                ?>
                                <img class="<?php echo $file3_md5_str; ?>" src="<?php echo $this->basePath($this->slide_array[2]['dbapi_ad_slide_image']); ?>" border="0" style="max-width:500px;" />
                                <a href="javascript:;" class="badge badge-important <?php echo $file3_md5_str; ?>" onclick="del_slide_image(<?php echo $this->ad['dbapi_ad_id']; ?>, '<?php echo $this->slide_array[2]['dbapi_ad_slide_image']; ?>');" title="<?php echo $this->translate('删除图片'); ?>">X</a>
                                <input class="<?php echo $file3_md5_str; ?>" type="hidden" name="old_ad_slide_image_3" value="<?php echo $this->slide_array[2]['dbapi_ad_slide_image']; ?>" />
                                <br class="<?php echo $file3_md5_str; ?>" />
                            <?php } ?>
                            <input type="file" name="ad_slide_image_3" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('显示文字3'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_slide_text_3" rows="2"><?php if($slide_content_2) echo $this->slide_array[2]['dbapi_ad_slide_info']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('链接地址3'); ?>：</label>
                        <div class="controls">
                            <input type="text"  name="ad_slide_url_3" class="span8" value="<?php if($slide_content_2) echo $this->slide_array[2]['dbapi_ad_slide_url']; ?>">
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('排序3'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="ad_slide_sort_3" value="<?php echo ($slide_content_2 ? $this->slide_array[2]['dbapi_ad_slide_sort'] : 3); ?>" class="span1" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('幻灯片图片4'); ?>：</label>
                        <div class="controls">
                            <?php $slide_content_3 = false; if($this->slide_array and !empty($this->slide_array[3])) { $slide_content_3 = true;
                                $file4_md5_str = md5($this->slide_array[3]['dbapi_ad_slide_image']);
                                ?>
                                <img class="<?php echo $file4_md5_str; ?>" src="<?php echo $this->basePath($this->slide_array[3]['dbapi_ad_slide_image']); ?>" border="0" style="max-width:500px;" />
                                <a href="javascript:;" class="badge badge-important <?php echo $file4_md5_str; ?>" onclick="del_slide_image(<?php echo $this->ad['dbapi_ad_id']; ?>, '<?php echo $this->slide_array[3]['dbapi_ad_slide_image']; ?>');" title="<?php echo $this->translate('删除图片'); ?>">X</a>
                                <input class="<?php echo $file4_md5_str; ?>" type="hidden" name="old_ad_slide_image_4" value="<?php echo $this->slide_array[3]['dbapi_ad_slide_image']; ?>" />
                                <br class="<?php echo $file4_md5_str; ?>" />
                            <?php } ?>
                            <input type="file" name="ad_slide_image_4" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('显示文字4'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_slide_text_4" rows="2"><?php if($slide_content_3) echo $this->slide_array[3]['dbapi_ad_slide_info']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('链接地址4'); ?>：</label>
                        <div class="controls">
                            <input type="text"  name="ad_slide_url_4" class="span8" value="<?php if($slide_content_3) echo $this->slide_array[3]['dbapi_ad_slide_url']; ?>">
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('排序4'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="ad_slide_sort_4" value="<?php echo ($slide_content_3 ? $this->slide_array[3]['dbapi_ad_slide_sort'] : 4); ?>" class="span1" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('幻灯片图片5'); ?>：</label>
                        <div class="controls">
                            <?php $slide_content_4 = false; if($this->slide_array and !empty($this->slide_array[4])) { $slide_content_4 = true;
                                $file5_md5_str = md5($this->slide_array[4]['dbapi_ad_slide_image']);
                                ?>
                                <img class="<?php echo $file5_md5_str; ?>" src="<?php echo $this->basePath($this->slide_array[4]['dbapi_ad_slide_image']); ?>" border="0" style="max-width:500px;" />
                                <a href="javascript:;" class="badge badge-important <?php echo $file5_md5_str; ?>" onclick="del_slide_image(<?php echo $this->ad['dbapi_ad_id']; ?>, '<?php echo $this->slide_array[4]['dbapi_ad_slide_image']; ?>');" title="<?php echo $this->translate('删除图片'); ?>">X</a>
                                <input class="<?php echo $file5_md5_str; ?>" type="hidden" name="old_ad_slide_image_5" value="<?php echo $this->slide_array[4]['dbapi_ad_slide_image']; ?>" />
                                <br class="<?php echo $file5_md5_str; ?>" />
                            <?php } ?>
                            <input type="file" name="ad_slide_image_5" />
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('显示文字5'); ?>：</label>
                        <div class="controls">
                            <textarea class="span6" name="ad_slide_text_5" rows="2"><?php if($slide_content_4) echo $this->slide_array[4]['dbapi_ad_slide_info']; ?></textarea>
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('链接地址5'); ?>：</label>
                        <div class="controls">
                            <input type="text"  name="ad_slide_url_5" class="span8" value="<?php if($slide_content_4) echo $this->slide_array[4]['dbapi_ad_slide_url']; ?>">
                        </div>
                    </div>
                    <div class="control-group ad_type_class ad_slide" style="display:none">
                        <label for="input01" class="control-label"><?php echo $this->translate('排序5'); ?>：</label>
                        <div class="controls">
                            <input type="text" name="ad_slide_sort_5" value="<?php echo ($slide_content_4 ? $this->slide_array[4]['dbapi_ad_slide_sort'] : 5); ?>" class="span1" />
                        </div>
                    </div>
                    <div class="control-group ad_url">
                        <label for="input01" class="control-label"><?php echo $this->translate('广告URL地址'); ?>：</label>
                        <div class="controls">
                            <input type="text" id="dbapi_ad_url"  name="dbapi_ad_url" class="span8" value="<?php echo (($this->ad and isset($this->ad['dbapi_ad_url'])) ? $this->escapeHtml($this->ad['dbapi_ad_url']) : ''); ?>">
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </form>
</div>
<?php echo $this->partial('common/editor',array('edit_array'=>array('ad_text'),
    'edit_config'=>array(
        "toolbars:[['FullScreen', 'Source', 'Undo', 'Redo','Bold']]",
        "wordCount:false",
        "initialFrameHeight:100",
        "elementPathEnabled:false",
        "maximumWords:500"
    )));
?>
<script>
    //客户分组保存验证
    $(document).ready(function() {
        $("#ad_form").validate({
            rules: {
                dbapi_ad_type: {
                    required: true
                }
            },
            messages: {
                dbapi_ad_type: {
                    required: "<?php echo $this->translate('广告类型不能为空！'); ?>"
                }
            }
        });
    });
    //切换广告类型
    function change_ad_type() {
        var ad_type = $('#dbapi_ad_type').val();
        $('.ad_type_class').css('display', 'none');
        if(ad_type != '') {
            $('.ad_'+ad_type).css('display', '');
            if(ad_type == 'slide') $('.ad_url').css('display', 'none'); else $('.ad_url').css('display', '');

            //调用推荐尺寸
            show_image_size();
        }
    }
    <?php if ($this->ad) { ?>
    change_ad_type();
    <?php } ?>

    function del_slide_image(ad_id, image_path) {
        if(window.confirm('<?php echo $this->translate('您确实要删除该图片吗？'); ?>')) {
            $.post("<?php echo $this->url('dbapi/default',array('action'=>'delSlideImage')); ?>",{ad_id:ad_id,image_path:image_path},
                function(data){
                    if(data != 'false') {
                        $('.'+data).remove();
                        return true;
                    } else {
                        alert('<?php echo $this->translate('图片删除失败！'); ?>');
                    }
                });
        }
        return false;
    }
</script>